package com.china.school;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.*;

public class DruidDataSourceTest {
    public static void main(String[] args) throws SQLException {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("DruidDataSourceTest.xml");
        DataSource bean = ctx.getBean(DataSource.class);
        System.out.println(bean);
        Connection connection = bean.getConnection();
        String sql = "select * from sys_dept";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            System.out.println("id-->" + resultSet.getInt(1));
        }



    }
}
